﻿@model CNFM_CROCODILE_LOGO.Core.Domain.ViewModels.MenuModels

@{
    ViewData["Title"] = "菜单Add";
}

@section Scripts
    {
    <script type="text/javascript">
        var selfLayer = null, page = 1, active = null;
        layui.use(['form', 'layedit'], function () {
            var form = layui.form, authtree = layui.authtree;

            axios.get('/Menu/MenuSelect', {
            })
                .then(function (response) {
                    console.log(response.data);
                    if (response.data.code == 200) {
                        var resultdata = response.data.result.data;
                        var options = '<option value="0">请选择</option>';
                        for (var i = 0; i < resultdata.length; i++) {
                            options += '<option value="' + resultdata[i].id + '" >' + resultdata[i].name + '</option>';
                        }
                        $("#SuperionMenuId").html(options);
                        form.render();
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                });


            //监听提交
            form.on('submit(submit)', function (data) {
                // data.field

                var sql = 1;

                if ($('#SuperionMenuId option:selected').val() == 0) {
                    data.field.SuperionMenuId = $('#SuperionMenuId option:selected').val()
                    sql = 1
                }
                else {
                    data.field.SuperionMenuId = $('#SuperionMenuId option:selected').val();
                    sql = 2
                }

                data.field.Sql = sql;

                axios({
                    method: 'post',
                    url: '/Menu/AddUpdateMenuAll',
                    //headers: {
                    //    'content-type': 'application/x-www-form-urlencoded'
                    //},
                    headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },
                    data: data.field
                })
                    .then(function (response) {
                        console.log(response);
                        if (response.data.code == 200) {
                            javascript: history.go(-1);
                        } else {
                            alert(response.msg)
                        }

                    }).catch(function (error) {
                        console.log("添加失败!" + error);
                    });
                return false;
            });

        });
    </script>
}

<form class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">所属菜单</label>
        <div class="layui-input-inline">
            <select asp-for="SuperionMenuId" autocomplete="off" lay-verify="required" lay-search=""></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="MenuName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单编码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="MuCode">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea asp-for="Remarks" style="width:545px;height:100px"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" style="width: 100px" lay-submit="" lay-filter="submit">立即提交</button>
            <a style="width: 100px" class="layui-btn layui-btn-primary backIframe" asp-action="List">返回</a>
        </div>
    </div>
</form>

